package com.touni.utils;

/**
 * @ClassName : DemoMain
 * @Description :
 * @Author : lwq
 * @Date: 2021-04-02 14:07
 */
public class DemoMain {

    /*public static void main(String[] args) {
        int[] arr = {1,2,6};
        int find = 6;
        int low = 0;
        int high = arr.length -1;
        while (low <= high){
            int middle = (low + high) / 2;
            if (arr[middle] > find){
                high = middle - 1;
            } else if (arr[middle] < find){
                low = middle + 1;
            } else {
                System.out.println(middle);
                return;
            }
        }
        System.out.println("not find");
    }*/

/*    public static void main(String[] args) {
        int arr[] = {1,2,6,9,45,8,41,69,66,2};
        for (int i = 0; i < arr.length; i++) {
            int min = i;
            for (int j = i + 1; j < arr.length; j++) {
                if (arr[j] < arr[min]){
                    min = j;
                }
            }
            if (min != i){
                int temp = arr[min];
                arr[min] = arr[i];
                arr[i] = temp;
            }
        }
        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
    }*/
/*
    public static void main(String[] args) {
        int[] arr = {16,6,5,9,10,59,3,54,49,89,3,5};

        quickSort(arr,0,arr.length-1);

        for (int i = 0; i < arr.length; i++) {
            System.out.print(arr[i] + " ");
        }
    }

    public static void quickSort(int[] arr ,int low,int high){
        if (low >= high){
            return;
        }
        int reference = arr[low];
        int i = low + 1;
        int j = high;
        while (i < j){
            //从右边开始 寻找比参考位置更小的值的索引取出其下标
            while (arr[j] > reference && i < j){
                j--;
            }
            //从左边开始，寻找比参考位置更大的值的索引取出其下标
            while (arr[i] < reference && i < j){
                i ++;
            }
            if (i < j){
                int temp = arr[i];
                arr[i] = arr[j];
                arr[j] = temp;
            }
        }
        //遍历到i=j的时候  将参考位置与中间位置对调
        if (i == j && arr[i] < reference){
            arr[low] = arr[i];
            arr[i] = reference;
        }
        //排序左半部分的值
        quickSort(arr,low,i-1);
        //排序右半部分的值  注意参考位置需要考虑进来
        quickSort(arr,i,high);
    }*/

}
